var app = getApp();
const { ajax_request } = require("../../utils/request_util");
Page({
  data: {},
  onLoad: function (options) {
    this.setScrollView();
    this.modal = this.selectComponent("#modal");
    console.log(this.modal)
  },
  showModal: function () {
    this.modal.showModal(); //调用组件中打开模态框方法
  },

  onShow: function () {
    this.qryEstateCondition();
  },
  async getSearchKey(e) {
    console.log("🚀 ~ file: index.js ~ line 9 ~ getSearchKey ~ e", e);
  },
  async setScrollView() {
    let that = this;
    let screenHeight = app.globalData.screenHeight;
    let navBarHeight = app.globalData.navBarHeight;
    const query = wx.createSelectorQuery();
    query.select(".other").boundingClientRect();
    query.exec(function (res) {
      let { height } = res[0] || {
        height: 0,
      };
      that.setData({
        scrollViewHeight: screenHeight - navBarHeight * 2 - height,
        scrollViewTop: navBarHeight + height,
      });
    });
  },
  async pullRefresh(e) {
    let hasData = false;
    this.setData({
      hasData,
    });
    if (e) {
      e.detail.resolve(hasData);
    }
  },
  async pushRefresh(e) {
    let hasData = false;
    this.setData({
      hasData,
    });
    if (e) {
      e.detail.resolve(hasData);
    }
  },
  async qryCusListCondition() {
    let res = await ajax_request("/cus/qryCusListCondition");
    let {
      body: { intentStars, cusStatus, cusFroms },
    } = res;
    let data1 = {
      title: "客户来源",
      searchType: "singleChoice",
      data: cusFroms,
      searchKey: "cusFrom",
    };
    let data2 = {
      title: "意向度",
      searchType: "multipleChoice",
      data: intentStars,
      searchKey: "intentStar",
    };
    let data3 = {
      title: "客户进度",
      searchType: "multipleChoice",
      data: cusStatus,
      searchKey: "cusStatus",
    };
    let searchData = [];
    searchData.push(data1);
    searchData.push(data2);
    searchData.push(data3);
    this.setData({
      searchData,
    });
  },
  async qryEstateCondition() {
    let res = await ajax_request("/estateSearch/qrySearchCondition", {
      cityCode: 511600,
    });
    let {
      body: {
        cityArea,
        renovationConditions,
        buildAreas,
        saleStatus,
        houseTypes,
        propertyCategorys,
        estateSort,
      },
    } = res;
    let searchData = [];
    let data1 = {
      title: "区域",
      searchType: "secondaryLinkage",
      data: cityArea,
      searchKey: "cityArea",
    };
    let data2 = {
      title: "排序",
      searchType: "singleSort",
      data: estateSort,
      searchKey: "estateSort",
    };
    let data4 = {
      title: "类型",
      searchType: "multipleChoice",
      data: propertyCategorys,
      searchKey: "propertyCategory",
    };
    let data5 = {
      title: "状态",
      searchType: "multipleChoice",
      data: saleStatus,
      searchKey: "saleStatus",
    };
    let moreData = [];
    let data6 = {
      title: "装修程度",
      searchType: "singleChoice",
      data: renovationConditions,
      searchKey: "renovationCondition",
    };
    let data3 = {
      title: "更多",
      searchType: "more",
      data: moreData,
      searchKey: "saleStatus",
    };
    moreData.push(data4);
    moreData.push(data5);
    moreData.push(data6);

    moreData.push(data2);

    searchData.push(data1);
    searchData.push(data2);
    searchData.push(data3);
    this.setData({
      searchData,
    });
  },
});
